﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace UtilityLibrary
{
    public class PointMath
    {

        public static bool IsPointInRectangle(Vector2 point, Rectangle rect, float rotation)
        {
            Vector2 pointToTest = point;
            pointToTest.X = pointToTest.X - rect.Center.X;
            pointToTest.Y = pointToTest.Y - rect.Center.Y;

            float rotationPrime = rotation;

            double xPrime = (pointToTest.X * Math.Cos(rotationPrime) + pointToTest.Y * Math.Sin(rotationPrime));
            double yPrime = (-pointToTest.X * Math.Sin(rotationPrime) + pointToTest.Y * Math.Cos(rotationPrime));

            xPrime = xPrime + rect.Center.X;
            yPrime = yPrime + rect.Center.Y;

            bool horizontalCollision = (xPrime >= rect.Left) && (xPrime <= rect.Right);
            bool verticalCollision = (yPrime >= rect.Top) && (yPrime <= rect.Bottom);

            return horizontalCollision && verticalCollision;
        }
    }
}
